package com.yp.infrastructure.demo.config.i18n;

import com.yp.infrastructure.mvc.i18n.I18nAbstractMessageSourceManager;
import com.yp.infrastructure.mvc.i18n.IMessageSourceManager;
import com.yp.infrastructure.mvc.i18n.IMessageSourceProvider;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class PartnerMessageConfiguration extends I18nAbstractMessageSourceManager implements IMessageSourceProvider {


    private static ReloadableResourceBundleMessageSource partnerMessageSource = null;

    @Bean
    public MessageSource partnerMessageSource() {
        if (null == partnerMessageSource) {
            partnerMessageSource = new ReloadableResourceBundleMessageSource();
            partnerMessageSource.setBasename("classpath:message.partner");
            partnerMessageSource.setDefaultEncoding("UTF-8");
        }
        return partnerMessageSource;
    }

    @Override
    public IMessageSourceManager create() {
        return this::partnerMessageSource;
    }

    @Override
    public MessageSource getMessageSource() {
        return partnerMessageSource();
    }
}
